function e(e) {
    for (var a = t.data.rulelist, n = {
        pay_code: "",
        old_price: 0,
        now_price: 0
    }, r = 0; r < a.length; r++) if (e > 0) {
        if (a[r].pay_day > 0) {
            n = a[r];
            break;
        }
    } else if (a[r].pay_gold > 0) {
        n = a[r];
        break;
    }
    return n;
}

var t, a, n = require("../../utils/util.js");

Page({
    data: {
        paywarp: !0,
        paytype: 1,
        curcode: "",
        old_price: 0,
        now_price: 0,
        isvip: 0,
        islogin: 0
    },
    onLoad: function() {
        t = this;
        var e = wx.getSystemInfoSync();
        this.setData({
            platform: e.platform
        });
    },
    onShow: function() {
        a = 1, this.setData({
            paywarp: !0
        }), n.getToken(function(e) {
            n.sendrequest("posterapi/person", "POST", {
                token: e
            }, function(e) {
                1 == e.status && (t.setData({
                    userinfo: e.data.userinfo,
                    isvip: e.data.isvip,
                    collectnum: e.data.collectnum,
                    mcount: e.data.mcount
                }), e.data.userinfo.phone_logo && t.setData({
                    islogin: 1
                }));
            });
        }), n.sendrequest("payapi/payrule", "POST", "", function(e) {
            1 == e.status && t.setData({
                rulelist: e.data.paylist
            });
        });
    },
    showpay: function(t) {
        var a = e(t.currentTarget.dataset.type);
        this.setData({
            paytype: t.currentTarget.dataset.type,
            paywarp: !1,
            old_price: a.old_price,
            now_price: a.now_price,
            curcode: a.pay_code
        });
    },
    closewarp: function(e) {
        this.setData({
            paywarp: !0
        });
    },
    changetype: function(t) {
        var a = 1 == this.data.paytype ? 0 : 1, n = e(a);
        this.setData({
            paytype: a,
            old_price: n.old_price,
            now_price: n.now_price,
            curcode: n.pay_code
        });
    },
    checkboxChange: function(e) {
        a = e.detail.value[0] > 0 ? 1 : 0;
    },
    showlog: function(e) {
        wx.navigateTo({
            url: "/pages/log/log?type=" + e.currentTarget.dataset.type
        });
    },
    showmemberinfo: function(e) {
        wx.navigateTo({
            url: "/pages/memberinfo/memberinfo"
        });
    },
    selectpay: function(e) {
        this.setData({
            curcode: e.currentTarget.dataset.code
        });
        for (var a = t.data.rulelist, n = 0; n < a.length; n++) e.currentTarget.dataset.code == a[n].pay_code && this.setData({
            old_price: a[n].old_price,
            now_price: a[n].now_price
        });
    },
    login: function(e) {
        if (e.detail.userInfo) {
            var t = e.detail.userInfo;
            n.getToken(function(e) {
                var a = {
                    token: e,
                    nickname: t.nickName,
                    avatarurl: t.avatarUrl,
                    gender: t.gender,
                    province: t.province,
                    city: t.city,
                    country: t.country
                };
                n.sendrequest("userapi/setuserinfo", "POST", a, function(e) {
                    1 == e.status && wx.reLaunch({
                        url: "/pages/center/center"
                    });
                });
            });
        }
    },
    getsignpack: function(e) {
        if (a < 1) return wx.showToast({
            title: "请同意会员协议"
        }), !1;
        t.data.curcode && n.getToken(function(e) {
            n.sendrequest("payapi/createorder", "POST", {
                token: e,
                code: t.data.curcode
            }, function(e) {
                1 == e.status && wx.requestPayment({
                    timeStamp: e.data.timeStamp,
                    nonceStr: e.data.nonceStr,
                    package: "prepay_id=" + e.data.prepayId,
                    signType: "MD5",
                    paySign: e.data.paySign,
                    success: function(e) {
                        wx.showToast({
                            title: "支付成功",
                            icon: "success",
                            duration: 2e3
                        }), wx.reLaunch({
                            url: "/pages/center/center"
                        });
                    },
                    fail: function(e) {}
                });
            });
        });
    }
});